package com.example.springsecuritydemo.config;

import com.alibaba.fastjson2.JSON;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {

        HashMap result = new HashMap();
        result.put("code",200);
        result.put("msg","注销成功");

        String json= JSON.toJSONString(result);

        //相应JSON结果，返回json数据给前端
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().println(json);
    }
}
